
<?php
require_once 'DBProperties.php';

class DBConnectionManager{

	private static $instance = null;
	private static $connection = null;

	private function __construct($userName, $password, $host, $database){
		self::$connection = mysql_connect($host, $userName, $password);
		mysql_select_db($database, self::$connection);
	}

	static private function getInstance() {

		if(is_null(self::$instance)){
			$dbProperties = new DBProperties();
			self::$instance = new DBConnectionManager($dbProperties -> getUserName(),
			$dbProperties -> getPassword(), $dbProperties -> getHost(), $dbProperties -> getDatabase());
		}

		return self::$instance;
	}

	static public function query($SQL) {

		self::getInstance();
		return @mysql_query($SQL, self::$connection);
	}
	
	static public function num_of_rows($SQL) {
		
		return @mysql_num_rows(self::query($SQL));
	}	
	
	static public function close(){
		mysql_close(self::$connection);
	}
}

?>
